﻿using NUnit.Framework;
using Inovout.Descriptors;
using Inovout.Models;

namespace Inovout.Service.Tests.Model
{
    [TestFixture]
    public class StringIdDataObjectTestCase
    {
        private StringIdDataObject testIdValueDataObject_Null;
        private StringIdDataObject testIdValueDataObject_Empty;
        private StringIdDataObject testIdValueDataObject_a;
        private StringIdDataObject targetIdValueDataObject_Null;
        private StringIdDataObject targetIdValueDataObject_Empty;
        private StringIdDataObject targetIdValueDataObject_a;
        private StringIdDataObject targetIdValueDataObject_b;

        [SetUp]
        public void TestInitialize()
        {
            FieldDescriptor idFieldDescriptor = new TypeDescriptor(typeof(StringIdDataObject)).GetField("id");

            testIdValueDataObject_Null = new StringIdDataObject();
            testIdValueDataObject_Empty = new StringIdDataObject();
            idFieldDescriptor.SetValue(testIdValueDataObject_Empty, string.Empty);
            testIdValueDataObject_a = new StringIdDataObject();
            idFieldDescriptor.SetValue(testIdValueDataObject_a, "a");

            targetIdValueDataObject_Null = new StringIdDataObject();
            targetIdValueDataObject_Empty = new StringIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_Empty, string.Empty);
            targetIdValueDataObject_a = new StringIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_a, "a");
            targetIdValueDataObject_b = new StringIdDataObject();
            idFieldDescriptor.SetValue(targetIdValueDataObject_b, "b");
        }
        [Test]
        public void EqualsTest()
        {
            bool expected;
            bool actual;
            //Null-Null
            expected = false;
            actual = testIdValueDataObject_Null.Equals(null);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Null.Equals(null)");


            #region Test_Null

            //Null
            expected = false;
            actual = testIdValueDataObject_Null.Equals(targetIdValueDataObject_Null);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Null.Equals(targetIdValueDataObject_Null)");

            //Empty
            expected = false;
            actual = testIdValueDataObject_Null.Equals(targetIdValueDataObject_Empty);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Null.Equals(targetIdValueDataObject_Empty)");


            //a
            expected = false;
            actual = testIdValueDataObject_Null.Equals(targetIdValueDataObject_a);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Null.Equals(targetIdValueDataObject_a)");

            //b
            expected = false;
            actual = testIdValueDataObject_Null.Equals(targetIdValueDataObject_b);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Null.Equals(targetIdValueDataObject_b)");

            #endregion

            #region Test_Empty

            //Null
            expected = false;
            actual = testIdValueDataObject_Empty.Equals(targetIdValueDataObject_Null);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Empty.Equals(targetIdValueDataObject_Null");

            //Empty
            expected = false;
            actual = testIdValueDataObject_Empty.Equals(targetIdValueDataObject_Empty);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Empty.Equals(targetIdValueDataObject_Empty)");

            //a
            expected = false;
            actual = testIdValueDataObject_Empty.Equals(targetIdValueDataObject_a);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Empty.Equals(targetIdValueDataObject_a)");

            //b
            expected = false;
            actual = testIdValueDataObject_Empty.Equals(targetIdValueDataObject_b);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_Empty.Equals(targetIdValueDataObject_b)");


            #endregion

            #region Test_a

            //Null
            expected = false;
            actual = testIdValueDataObject_a.Equals(targetIdValueDataObject_Null);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_a.Equals(targetIdValueDataObject_Null");

            //Empty
            expected = false;
            actual = testIdValueDataObject_a.Equals(targetIdValueDataObject_Empty);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_a.Equals(targetIdValueDataObject_Empty)");

            //a
            expected = true;
            actual = testIdValueDataObject_a.Equals(targetIdValueDataObject_a);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_a.Equals(targetIdValueDataObject_a)");

            //b
            expected = false;
            actual = testIdValueDataObject_a.Equals(targetIdValueDataObject_b);
            Assert.AreEqual(expected, actual, "testIdValueDataObject_a.Equals(targetIdValueDataObject_b)");


            #endregion
        }

        [Test]
        public void GetHashCodeTest()
        {
            int expected;
            int actual;
            #region Test_Null
            expected = (0).GetHashCode();
            actual = testIdValueDataObject_Null.GetHashCode();
            Assert.AreNotEqual(expected, actual, "testIdValueDataObject_Null.GetHashCode()");
            #endregion

            #region Source_Empty
            expected = string.Empty.GetHashCode();
            actual = testIdValueDataObject_Empty.GetHashCode();
            Assert.AreNotEqual(expected, actual, "testIdValueDataObject_Empty.GetHashCode()");

            #endregion

            #region Source_a
            expected = "a".GetHashCode();
            actual = testIdValueDataObject_a.GetHashCode();
            Assert.AreEqual(expected, actual, "testIdValueDataObject_a.GetHashCode()");

            #endregion
        }
        public class StringIdDataObject : DataObject
        {
        }
    }
}
